#ifndef _NNSLITE_HEAP_FILE_H_
#define _NNSLITE_HEAP_FILE_H_

#include "nnsliteglobal.h"

#define NNSLITE_HEAPFS_MAGIC_NUMBER 0x83092301

struct nnsliteHeapFS;

typedef struct nnsliteHeapPageHeader
{
	u32 usedSize;
	u32 state;
}nnsliteHeapPageHeader;

typedef struct nnsliteHeapFile
{
	u32 hfd;
	u32 startPageIndex;
	u32 lastPageIndex;
	u64 length;
	u64 capacity;
	bool isUsed;
	struct nnsliteHeapFS* heapFS;
}nnsliteHeapFile;

typedef struct nnsliteHeapFS
{
	u32  magicNumber;
	u32  structSize;
	char filename[NNSLITE_MAX_NAMELEN];
	int  fd;
	u32  defaultBufSize;
	u32  pageSize;
	u32  numPages;
	u32  maxNumFiles;
	u64  pageStoreOffset;
	nnsliteHeapPageHeader *pageAllocationTable;
	nnsliteHeapFile fileInfos[1];
}nnsliteHeapFS;


NNSLITE_RET nnsliteHeapFSOpenNew(nnsliteHeapFS** heapFS, const char* filename, u32 bufsize, u32 pagesize, u32 numpages, u32 maxfiles);
NNSLITE_RET nnsliteHeapFSClose(nnsliteHeapFS* heapFS);
NNSLITE_RET nnsliteHeapFSSave(nnsliteHeapFS* heapFS);
NNSLITE_RET nnsliteHeapFSOpen(nnsliteHeapFS** heapFS,  const char* filename);

NNSLITE_RET nnsliteHeapFileOpenNew(nnsliteHeapFS* heapFS, nnsliteHeapFile** heapFile, u32 hfd);
NNSLITE_RET nnsliteHeapFileDelete(nnsliteHeapFS* heapFS, u32 hfd);
NNSLITE_RET nnsliteHeapFileExisted(nnsliteHeapFS* heapFs, u32 hfd, bool* isExisted);
NNSLITE_RET nnsliteHeapFileOpen(nnsliteHeapFS* heapFS, u32 hfd, nnsliteHeapFile** heapFile);
NNSLITE_RET nnsliteHeapFileClose(nnsliteHeapFile* heapFile);
NNSLITE_RET nnsliteHeapFileAppend(nnsliteHeapFile* heapFile, const void* buf, u64 size);
NNSLITE_RET nnsliteHeapFileRead(nnsliteHeapFile* heapFile, u64 offset, void* buf, u64 size);



#endif

